<?php

namespace app\api\controller\cps;

use app\common\controller\Api;



/**
 * 淘宝客接口
 */
class Tbk extends Api
{
    protected $noNeedLogin = ['callback','orderlist'];
    protected $noNeedRight = ['*'];

    //活动列表
    public function material()
    {
        try {
            $page = input('page',1);
            $subject = input('subject',1);

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->material($page,$subject);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //商品列表
    public function goods()
    {
        try {
            $page = input('page',1);
            $material_id = input('material_id','');

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->goods($page,$material_id);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //查询商品列表
    public function searchgoods()
    {
        try {
            $page = input('page',1);
            $material_id = input('material_id','');
            $keyword = input('keyword','');
            $sort = input('sort','');
            $has_coupon = input('has_coupon',0);
            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->searchgoods($page,$material_id,$keyword,$sort,$has_coupon);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //商品详情
    public function goodsDetail()
    {
        try {

            $item_id = input('item_id','');

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->goodsdetail($item_id);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //淘宝客高佣转链
    public function privilege()
    {
        try {

            $item_id = input('item_id','');

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->privilege($item_id,$this->auth->id);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //官方活动链接
    public function activityUrl()
    {
        try {

            $activity_material_id = input('activity_material_id','');

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->activityUrl($activity_material_id,$this->auth->id);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //长链转短链
    public function changeShortUrl()
    {
        try {

            $url = input('url','');

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->changeShortUrl($url);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //淘口令生成
    public function wordCommandCreate()
    {
        try {

            $url = input('url','');

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->wordCommandCreate($url,$this->auth->id);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //私域用户备案
    public function savepublisher()
    {
        try {
            $invitecode = input('invitecode','');

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->savepublisher($invitecode);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //私域用户备案信息查询
    public function getpublisher()
    {
        try {

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->getpublisher();
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //私域用户邀请码生成
    public function invitecode()
    {
        try {

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->invitecode();
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    //订单列表
    public function orderlist()
    {
        try {

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->neworderlist();
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }

    public function unliquidated()
    {
        try {

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->unliquidated();
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }


    public function callback()
    {
        $code = input('code','');
        try {

            $jd_model = new \app\api\model\cps\Tbk();

            $res = $jd_model->callback($code);
        }  catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('请求成功',$res);
    }
}